package com.gy.training.ui;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;

import com.gy.training.R;

import butterknife.BindBool;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WiFiMgrActivity extends Activity {
    WifiManager wifiManager;
    @BindView(R.id.ban_btn) Button ban_btn;
    @BindView(R.id.switch_btn) Switch switch_btn;
    @BindBool(R.bool.is_able) boolean is_able;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wi_fi_mgr);
        ButterKnife.bind(WiFiMgrActivity.this);
        wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
        switch_btn.setChecked(true);
        switch_btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (buttonView.isChecked()) {
                    wifiManager.setWifiEnabled(true);
                } else {
                    wifiManager.setWifiEnabled(false);
                }
            }
        });
    }
    @OnClick({R.id.ban_btn})
    public void onclick(View view){
        switch (view.getId()){
            case R.id.ban_btn:
                if(is_able){
                    ban_btn.setText("启用switch按钮");
                    is_able = false;
                }else {
                    ban_btn.setText("禁用switch按钮");
                    is_able = true;
                }
                switch_btn.setEnabled(is_able);
                break;
            default:break;
        }
    }
}
